/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package plan.mobile;

import java.util.Iterator;
import mobile.Call;
import mobile.Message;
import mobile.MobileConsumption;
import plan.Plan;
import turnover.Consumption;

/**
 *
 * @author Ale
 */
public class Movistar_Contrato_Unico extends Plan {

    private double startQuote = 21.03d;
    private double minuteCost= 0.18d;
    private double minuteYoigoCost = 0.23d;
    private double messageCost = 0.15d;

    /*El Contrato Decreciente es compatible con todas las promociones Orange y
    con  todos los módulos de ahorro, a excepción de  Mis 5 de Orange.*/

    public Movistar_Contrato_Unico() {
        super.setName("Movistar Contrato Único");
    }

    public double getStartQuote() {
        return startQuote;
    }

    @Override
    public double getCost(Consumption consumption) {

        double total = 0d;
        MobileConsumption mc = (MobileConsumption) consumption;
        Iterator it = mc.getCallList().listIterator();
        long duration = 0;
        while (it.hasNext()) {
            Call c = (Call) it.next();

            if (c.isSpecial()) {
                total += c.getCost();
            }
            else if (this.IsYoigoCall(c)) {
                total += c.getDuration().changeSeconds() * this.minuteYoigoCost / 60;
                duration += c.getDuration().changeSeconds();
            }
            else{
                duration += c.getDuration().changeSeconds();
                total += c.getDuration().changeSeconds() * this.minuteCost / 60;

            }
        }

        it = mc.getMessList().listIterator();
        while (it.hasNext()) {
            Message m = (Message) it.next();
            if (m.isSpecial()) {
                total += m.getCost();
            } else {
                total += this.messageCost;
            }
        }
        if (total<9d){
            total = 9d;
        }
        total += total * 0.16d;
        return total;
    }

    public double getMessageCost() {
        return messageCost;
    }

    private boolean IsYoigoCall(Call c){
        return c.getOperador().getName().equals("Yoigo");
    }

    public double getMinuteCost() {
        return minuteCost;
    }
}

